
use "s1data.dta"

*PID
gen PID=pid
recode PID 1=2 2=6 3/4=4
recode PID 2=1 if pidd==1
recode PID 6=7 if pidr==1
recode PID 4=3 if pidi==1
recode PID 4=5 if pidi==2
replace PID=(PID-4)/3
recode PID -1/-.5=1 -.4/.4=2 .5/1=3, gen(PID3)
recode ideo 1/3=1 4=2 5/7=3, gen(ideo3)


*pretreatment group attitudes
rename groups_1 favasian
replace favasian=favasian/100

*policy attitude
rename policy_1 gunrestrict
replace gunrestrict=(gunrestrict-3)/2

*treatment indicator
gen treat_viet=.
replace treat_viet=0 if YI==1
replace treat_viet=1 if YF==1

*outcome variables
recode viet_favor 1=7 4=6 5=5 6=4 7=3 8=2 9=1
gen viet_favor01=(viet_favor-1)/6
gen viet_values01=(viet_values-1)/4
gen viet_close01=(viet_close-1)/3
sum viet_*01

*outcome index
alpha viet_values01 viet_close01 viet_favor01, item casewise gen(viet_index)


************
* analysis *
************

*manipulation checks - Table A1
reg viet_gun treat_viet
reg viet_pid treat_viet

*main analysis - Table A2
reg viet_index i.treat_viet##c.gunrestrict PID favasian
est store v1
margins, dydx(treat_viet) at(gunrestrict=(-1(.5)1))
marginsplot, yline(0) recast(line) recastci(rarea) ciopt(color(gs10%30)) xtitle("Gun Control") ytitle("Marginal Treatment Effect", size(small)) title("") ylab(-.2(.1).2) subtitle("Attitudes Toward Vietnamese Americans") addplot(hist gunrestrict, freq ysc(r(-.2 .2) axis(1))ylab(-.2(.1).2, axis(1)) yaxis(2) yscale(alt axis(2)) ytitle("Frequency", axis(2) size(small)) fcolor(none) bcolor(gs5%40)) legend(off) xlab(-1 `""Strongly" "favor""' -.5 `""Somewhat" "favor""' 0 "Neither" .5 `""Somewhat" "oppose""' 1 `""Strongly" "oppose""') saving(s1.gph, replace)

*Individual DVs - Table A2
reg viet_favor01 i.treat_viet##c.gunrestrict PID favasian
est store v2

reg viet_close01 i.treat_viet##c.gunrestrict PID favasian
est store v3

reg viet_values01 i.treat_viet##c.gunrestrict PID favasian
est store v4

*including PID interaction with treatment
reg viet_index i.treat_viet##c.gunrestrict i.treat_viet##c.PID favasian
est store v5
margins, dydx(treat_viet) at(gunrestrict=(1(1)5))
margins, dydx(treat_viet) at(PID=(-1(1)1))

esttab v1 v2 v3 v4 v5, drop(0.treat_viet*) se(2) b(2) r2(2)



*CACE

*compliance rates
recode viet_gun 0/50=0 51/100=1, gen(viet_gun_di)
tab viet_gun_di treat_viet, col chi2

*CACE and ITT among policy supporters
reg viet_index treat_viet favasian PID if gunrestrict<0
reg viet_gun_di treat_viet if gunrestrict<0
ivregress 2sls viet_index  (viet_gun_di=treat_viet) if gunrestrict<0

*CACE and ITT among policy opponents
reg viet_index treat_viet favasian PID if gunrestrict>0
reg viet_gun_di treat_viet if gunrestrict>0
ivregress 2sls viet_index (viet_gun_di=treat_viet) if gunrestrict>0



*table a1. demographics
tab sex
sum age, detail
tab race
tab educ
tab PID3
tab ideo3